﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace RemoteServer.Framework
{
    class Utils
    {
        //auth_key = md5(api_id + '_' + viewer_id + '_' + api_secret)
        internal static bool CheckMD5(string _auth_key, string _viewer_id)
        {
            string dataStr = string.Format("{0}_{1}_{2}", Configuration.ApplicationID, _viewer_id, Configuration.ApplicationSecretKey);
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            byte[] dataByteArray = encoding.GetBytes(dataStr);
            byte[] byteMD5 = MD5Hash(dataByteArray);
            string strMD5 = encoding.GetString(byteMD5);

            return strMD5 == _auth_key;
        }

        public static byte[] MD5Hash(byte[] data)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] result = md5.ComputeHash(data);
            return result;
        }
    }
}
